package com.fjnu.controller;

import com.fjnu.entity.Category;
import com.fjnu.uitl.ResponseResult;
import com.fjnu.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping("delete")
    public ResponseResult deleteCategory(Integer categoryId){
        int i = 0;
        ResponseResult responseResult = new ResponseResult();
        if (i > 0){
            responseResult.setCode("200");
            responseResult.setMessage("删除成功");
        }
        else{
            responseResult.setCode("500");
            responseResult.setMessage("删除失败");
        }
        return responseResult;
    }
    @PostMapping("add")
    public ResponseResult insertCategory(Category category){
        int i = categoryService.add(category);
        ResponseResult responseResult = new ResponseResult();
        if (i > 0){
            responseResult.setCode("200");
            responseResult.setMessage("添加成功");
        }
        else{
            responseResult.setCode("500");
            responseResult.setMessage("添加失败");
        }
        return responseResult;
    }
    @GetMapping("list")
    public ResponseResult listCategory(){
        List<Category> list = categoryService.list();
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage("查询成功");
        responseResult.setData(list);
        return responseResult;
    }
}
